package tralala.jdo;

import java.io.Serializable;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.jdo.Transaction;

import tralala.data.*;

public class Fichero_MPEGDAO {
	private PersistenceManager pm = null;
	
	public Fichero_MPEGDAO(){
		pm = TralalaDAO.getInstance().connect();
	}
	
	public void almacenar(Fichero_MPEG mpeg){
		Transaction tx = pm.currentTransaction();
		tx.begin();
		pm.makePersistent(mpeg);
		tx.commit();
	}
	
	public void eliminar(Fichero_MPEG mpeg){
		Transaction tx = pm.currentTransaction();
		tx.begin();
		pm.deletePersistent(mpeg);
		tx.commit();
	}
	
	public Fichero_MPEG obtenerFichero(String url){
		Fichero_MPEG mpeg = null;
		Transaction tx = pm.currentTransaction();
		tx.begin();
		Query query = pm.newQuery("SELECT FROM " + Fichero_MPEG.class.getName() + " WHERE url == '" + url + "'");
		query.setUnique(true);
		mpeg = (Fichero_MPEG)query.execute();
		tx.commit();
		return mpeg; 
	}
}
